<?php

/**
 * @author  zhe.wang
 * @desc    index
 */

namespace App\Http\Controllers\Api\V1\Demo;

use App\Http\Controllers\ApiBaseController;
use App\Libs\Commons\MyException;
use App\Libs\Commons\MyMessage;
use App\Services\Message\PushService;

class IndexController extends ApiBaseController
{

    private $PushService;


    public function __construct(PushService $PushService)
    {
        $this->PushService = $PushService;

    }
    /**
     * 短信推送
     */
    public function index()
    {
        print_r(123);exit;

    }
    /**
     * 云片 短信推送（需对接云片） true
     */
    public function smsdemo()
    {
        $data = [
            'mobile' => 'xxxxxxxxxxx',
            'text' => 'XXXXXXXXX'
        ];

        $res = $this->PushService->sms($data);
        print_r($res);
    }
    /**
     * 小程序推送
     */
    public function miniprogramdemo()
    {

        $data = [
            'template_id' => 'xxx',
            'touser' => 'xxx',
            'data' => [
                'thing1' => [
                    'value' => '维修服务',
                ],
                'thing2' => [
                    'value' => '待接车',
                ]
            ]
        ];
        $res = PushService::miniprogram($data);

    }
    /**
     * 企业微信推送
     */
    public function workdemo()
    {

        $data =[
            //企业微信id
            'touser' => 'xxxxxx',
            'title' => 'hello world',
            'description' => 'hello world',
            'url' => 'xxxx',
        ];
        $res = PushService::work($data);
		print_r($res);

	}

    /**
     * 返回信息示例
     * @return \Illuminate\Http\JsonResponse
     */
    public function My_success()
    {
        $data = [
            'name'	=> 'wangzhe',
            'age'	=> 27
        ];
        return My_success($data);

    }

	// 筛选指定内容
	public function matchAttr($param = [], $filter = [])
	{
		if (empty($param)) {
			return [];
		}

		$arr = [];
		foreach ($param as $v) {

			$v['ProductNo'] = str_replace(' ', '', $v['ProductNo']);

			if (!empty($v['ProductCategoryName'])) {
				// 多条件筛选   
				if (!empty($filter['name']) && !empty($filter['no'])) {
					if ($v['ProductCategoryName'] == $filter['name'] && str_replace(' ', '', $v['ProductNo']) == $filter['no']) {
						$arr[] = $v;
						break;
					}
				}

				if ($v['ProductCategoryName'] == $filter['name']) {
					$arr[] = $v;
				}
			}
		}
		return $arr;
	}


	public function test()
	{
		$param = request()->all();
		$client = new \Yar_Client("http://xx.xx.xx/rpc");
		$client->SetOpt(YAR_OPT_HEADER, ["token: xxxxxx"]);
		$result = $client->execute([
			'method' => 'mutual.UserAssessment.update',
			'data' => $param
		]);
		print_r($result);
	}
}
